package com.bysj.lms.controller;


import com.bysj.lms.common.ResultModel;
import com.bysj.lms.pojo.entity.LmsEm;
import com.bysj.lms.service.ILmsEmService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaojiakai
 * @since 2022-02-04
 */
@RestController
@RequestMapping("/lms-em")
@Api(tags = "维修管理")
public class LmsEmController {

    @Autowired
    ILmsEmService lmsEmService;
    
    @ApiOperation("得到维修模型")
    @GetMapping()
    public LmsEm getModel(){
        return new LmsEm();
    }
    
    @ApiOperation("查看维修列表")
    @GetMapping("/list")
    public ResultModel getList(Integer page,Integer count,String status){
        PageInfo list = lmsEmService.getList(page, count,status);
        return ResultModel.success("查询成功",list);
    }
    
    @ApiOperation("申请维修")
    @PostMapping("/ApplyMaintenance")
    public ResultModel applyMaintenance(@RequestBody LmsEm lmsEm){
        boolean save = lmsEmService.apply(lmsEm);
        return save?ResultModel.success("申请成功"):ResultModel.failure("申请失败");
    }
    
    @ApiOperation("处理维修")
    @PutMapping("/handle")
    public ResultModel handle(@RequestBody LmsEm lmsEm){
        boolean handle = lmsEmService.handle(lmsEm);
        return handle?ResultModel.success():ResultModel.failure();
    }
    
    @ApiOperation(value = "完成处理",notes = "属性只需要id，handleProcess,handleResult")
    @PutMapping("/accomplish")
    public ResultModel accomplish(@RequestBody LmsEm lmsEm){
        boolean finish = lmsEmService.finish(lmsEm);
        return finish?ResultModel.success():ResultModel.failure();
    }
    
    @ApiOperation(value = "修改")
    @PutMapping("/edit")
    public ResultModel edit(@RequestBody LmsEm lmsEm){
        boolean update = lmsEmService.updateById(lmsEm);
        return update?ResultModel.success():ResultModel.failure();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/delete")
    public ResultModel delete(String id){
        boolean b = lmsEmService.removeById(id);
        return b?ResultModel.success():ResultModel.failure();
    }
}

